package com.kiss.rpc.config;

import com.kiss.rpc.IdGenerator;
import com.kiss.rpc.discovery.RegistryConfig;
import com.kiss.rpc.loadbalancer.LoadBalancer;
import com.kiss.rpc.loadbalancer.impl.RoundRobinLoadBalancer;
import com.kiss.rpc.protection.CircuitBreaker;
import com.kiss.rpc.protection.RateLimiter;
import lombok.Data;

import java.net.SocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Data
public class Configuration {
    private int port = 8094;

    private String appName = "default";

    private String group = "default";

    private RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:2181");

    // 配置信息-->序列化协议
    private String serializeType = "jdk";

    // 配置信息-->压缩使用的协议
    private String compressType = "gzip";

    // 配置信息-->id发射器
    public IdGenerator idGenerator = new IdGenerator(1, 2);

    // 配置信息-->负载均衡策略
    private LoadBalancer loadBalancer = new RoundRobinLoadBalancer();

    // 为每一个ip配置一个限流器
    private final Map<SocketAddress, RateLimiter> everyIpRateLimiter = new ConcurrentHashMap<>(16);
    // 为每一个ip配置一个断路器，熔断
    private final Map<SocketAddress, CircuitBreaker> everyIpCircuitBreaker = new ConcurrentHashMap<>(16);

    public Configuration() {
        // 1、成员变量的默认配置项

//        // 2、spi机制发现相关配置项
//        SpiResolver spiResolver = new SpiResolver();
//        spiResolver.loadFromSpi(this);
//
//        // 3、读取xml获得上边的信息
//        XmlResolver xmlResolver = new XmlResolver();
//        xmlResolver.loadFromXml(this);

        // 4、编程配置项，yrpcBootstrap提供
    }
}
